import java.util.Arrays;

public class testSort {
    public static void main(String[] args) {
        int[] arr ={1,3,5,6,7,11,45,2,4};
        int[] arr2 ={1,3,5,6,88,23,45,534,7,11,45,2,4};
        int[] sort = sort(arr);
        int[] sort2 = quickSort(arr2,0,arr2.length-1);
        System.out.println("sort = " + Arrays.toString(sort));
        System.out.println("sort = " + Arrays.toString(sort2));
    }
    private static int[] sort(int[] arr){
        for(int i = 0;i < arr.length - 1;i++){
            for(int j = 0;j< arr.length - i-1;j++){
                if(arr[j]<arr[j+1]){
                    int temp = arr[j+1];
                    arr[j+1] = arr[j];
                    arr[j] = temp;
                }
            }
        }
        return arr;
    }
    private static int quickSort1(int[] arr,int start,int end){
        int s = start;
        int e = end;
        int key = arr[start];
        while(s < e){
            while(s < e && arr[e]>= key) {
                e--;
            }
            if(s < e){
                arr[s] = arr[e];
                s++;
            }

            while (s < e && arr[s] < key) {
                s++;
            }
            if(s < e) {
                arr[e] = arr[s];
                e--;
            }
        }
        arr[s] = key;
        return s;
    }
    private static  int[] quickSort(int[] arr,int start,int end){
        if(start < end){
            int keyIndex = quickSort1(arr,start,end);
            quickSort(arr,start,keyIndex-1);
            quickSort(arr,keyIndex+1,end);
        }
        return arr;
    }
}
